<?php
/**
 * Created by PhpStorm.
 * User: nikolai
 * Date: 11/12/13
 * Time: 22:51
 */
echo 'Hello bitch';
?>
<table width="400" border="0" align="center" cellpadding="3" cellspacing="0">
<tr>
<td><strong>Leave a comment</strong></td>
</tr>
</table>
<table width="400" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<form id="form1" name="form1" method="post" action="">
<td>
<table width="400" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td width="117">Name</td>
<td width="14">:</td>
<td width="357"><input name="name" type="text" id="name" size="40" /></td>
</tr>
<tr>
<td>Email</td>
<td>:</td>
<td><input name="email" type="text" id="email" size="40" /></td>
</tr>
<tr>
<td valign="top">Comment</td>
<td valign="top">:</td>
<td><textarea name="comment" cols="40" rows="3" id="comment"></textarea></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td><input type="submit" name="Submit" value="Submit" /></td>
</tr>
</table>
</td>
</form>
</tr>
</table>
<table width="400" border="0" align="center" cellpadding="3" cellspacing="0">
</table>
<?php
if (isset($_POST['Submit'])) {
    $host="localhost"; // Host name
    $username="root"; // Mysql username
    $password="root"; // Mysql password
    $db_name="vibestattoo"; // Database name
    $tbl_name="guestbook"; // Table name

    // Connect to server and select database.
    mysql_connect("$host", "$username", "$password")or die("cannot connect server ");
    mysql_select_db("$db_name")or die("cannot select DB");

    $datetime=date("y-m-d h:i:s"); //date time

    $sql="INSERT INTO $tbl_name(name, email, comment, datetime)VALUES('$name', '$email', '$comment', '$datetime')";
    $result=mysql_query($sql);

    //check if query successful
    if($result){
        echo "Successful";
        echo "<BR>";

    // link to view guestbook page
        echo "<a href='viewguestbook.php'>View guestbook</a>";
    }

    else {
        echo "ERROR";
    }
    mysql_close();
}
?>